package ar.edu.sovietrussia.customcomponents.loaning;

import java.util.Map;

import org.apache.wicket.authroles.authorization.strategies.role.annotations.AuthorizeInstantiation;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Button;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.panel.FeedbackPanel;

import ar.edu.sovietrussia.customcomponents.util.BackToMainWindowGenericComponent;
import ar.edu.sovietrussia.customcomponents.util.WrapperPanel;

/**
 * Showed when the user can not loan a book and need to reserve it
 */
@AuthorizeInstantiation({ "USER", "ADMIN" })
public abstract class NeedToReserveComponent extends BackToMainWindowGenericComponent {

    private static final long serialVersionUID = -3526561483814996169L;

    public NeedToReserveComponent(final String id) {
        super(id);

        Form<String> form = new Form<String>("confirmReserveForm");

        form.add(new Label("descriptionLabel", "Libro no disponible. "));
        form.add(new Label("questionLabel", "Desea gestionar una reserva?"));

        // Accept Button
        form.add(new Button("accept_button") {
            private static final long serialVersionUID = 5119888790644143879L;

            @Override
            public void onSubmit() {
                NeedToReserveComponent.this.replaceWith(new ReservationSucceededComponent(NeedToReserveComponent.this
                        .getId()) {

                    private static final long serialVersionUID = 1L;

                    @Override
                    public FeedbackPanel getFeedbackTarget() {
                        return NeedToReserveComponent.this.getFeedbackTarget();
                    }

                    @Override
                    public Map<String, WrapperPanel> getReplaceableComponents() {
                        return NeedToReserveComponent.this.getReplaceableComponents();
                    }

                });
            }

        });

        // Cancel Button
        form.add(new Button("cancel_button") {
            private static final long serialVersionUID = 5119888790644143879L;

            @Override
            public void onSubmit() {
                NeedToReserveComponent.this.goBack();
            }

        });

        this.add(form);
    }

}
